import { Button, Form, Input, InputNumber } from 'antd';
import { message, Upload } from 'antd';
import { BackTop } from 'antd';
import React from 'react';
// const {  Upload, message  } = antd;
import { UploadOutlined } from '@ant-design/icons';
import { Link } from 'react-router-dom';
import style from './index.less';
import request from '@/http';
import All_style from '../../../index.less';

const props = {
  name: 'file',
  action: 'https://10.8.21.181:8087',
  headers: {
    authorization: 'authorization-text',
  },
  onChange(info) {
    if (info.file.status !== 'uploading') {
      console.log(info.file, info.fileList);
    }
    if (info.file.status === 'done') {
      message.success(`${info.file.name} file uploaded successfully`);
    } else if (info.file.status === 'error') {
      message.error(`${info.file.name} file upload failed.`);
    }
  },
  progress: {
    strokeColor: {
      '0%': '#108ee9',
      '100%': '#87d068',
    },
    strokeWidth: 3,
    format: (percent) => `${parseFloat(percent.toFixed(2))}%`,
  },
};
const { TextArea } = Input;

const replyWork = (prop: any) => {
  const [formObject] = Form.useForm();
  // 得到上个页面传参
  let wc_id;
  let wc_state;
  if (prop.location && prop.location.state) {
    wc_id = prop.location.state.wc_id;
    wc_state = prop.location.state.wc_state;
  }
  /**
   * 上传文件，得到文件
   */
  const insertWork = (prop: any) => {
    var [fileList, setFileList] = React.useState([]);
    const [formObject] = Form.useForm();
    const test = async (e) => {
      // console.log(e.target.files)
      let formdata = new FormData();
      formdata.append('file', e.target.files[0]);
      // request.post('/homeWork_manager_module/fileUpload', formdata).then(res => {
      //   setFileList(res)
      //   console.log(filename);
      // })
      const result: any = await request.post('/common/a_t_s/upload', formdata);
      setFileList(result.data);
      console.log(result.data);
    };
    /**
     * 提交
     */
    const submit = async () => {
      const selectForm = await formObject.validateFields(); //获得表单数据
      const CourseName: any = await request.post(
        '/homework_manage/ask/tea_PiFu',
        {
          wc_id: wc_id,
          wc_state: 2,
          wc_score: selectForm.score,
          wc_enclosure: fileList,
          a: 0,
        },
      );
    };
    const submit1 = async () => {
      const selectForm = await formObject.validateFields(); //获得表单数据
      const CourseName: any = await request.post(
        '/homework_manage/ask/tea_PiFu',
        {
          wc_id: wc_id,
          wc_state: 1,
          wc_score: selectForm.score,
          wc_enclosure: selectForm.enclosure,
          a: 1,
        },
      );
    };

    return (
      <div className={All_style.box}>
        <Form form={formObject}>
          <Form.Item label="得分" name="score">
            <InputNumber placeholder="请输入"></InputNumber>
          </Form.Item>

          <Form.Item label="选择附件" name={'enclosure'}>
            <input type="file" onChange={test} />
          </Form.Item>
          <Form.Item>
            <TextArea rows={10} />
          </Form.Item>
        </Form>

        <div style={{ clear: 'both' }}>
          <Link to={'/Teacher/Assignment/Approval/index'}>
            <Button className={All_style.button} onClick={submit}>
              确认提交
            </Button>
          </Link>
          <Link to="/Teacher/Assignment/Approval/index">
            <Button className={All_style.button2} onClick={submit1}>
              保存草稿
            </Button>
          </Link>
        </div>
      </div>
    );
  };
};
export default replyWork;
